﻿
using Mate.Core.Base;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using System;

namespace Mate.Framework.Infrastructure
{
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
    public class AdminAuthenticationAttribute : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            //登录验证
            if (!filterContext.HttpContext.User.Identity.IsAuthenticated)
            {
                if (filterContext.HttpContext.Request.Method == "GET")
                {
                    filterContext.Result = new RedirectResult("/Login", false);
                    return;
                }
                else
                {
                    var result = new BaseResult();
                    result.ResultCode = ResultCode.LoginTimeOut;
                    result.Message = "登录已超时，请重新登录";
                    filterContext.Result = new JsonResult(result);
                    return;
                }
            }

           

        }
    }
}
